<?php
namespace App\Http\Controllers\Admin;

use App\Models\Area;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
/**
 *
 * @author Joker
 *        
 */
class AreaController extends BaseController
{
    public function index() 
    {
        if(!$this->user->can('viewContentArea'))
            abort(405);
        
        $category = Area::where(array('pid'=>0))->orderBy('area_id','ASC')->get();
        
        return view('admin.setting.area.list')->with('category',$category);
    }   
    
    /**
     *  热门板块
     */
    public function hotCates(Request $request)
    {
        if(!$this->user->can('viewContentArea'))
            return $this->formatJson('error','抱歉，您没有相关操作权限');
        
        $id = $request->input('id');
        $is_hot = $request->input('is_disabled');
        $question = Area::find($id);
    
        $question->is_hot = $is_hot == 1 ? 0 : 1;
        if ($question->save())
            return  Response::json(array('status'=>'success','msg'=>'成功', 'data' => $question->is_hot));
    }
}